﻿using HealthcareSystem.API.Read.Application.Command.Element.ElementCommand;
using HealthcareSystem.API.Read.DTO.Element;
using HealthcareSystem.Domain.BasicSettings.FormManagement;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Read.Application.CommandHandel.Element.ElementCommandHandler
{
    public class SelectElementCommandHandel : IRequestHandler<SelectElementCommand, ApiResult<List<SelectElementDto>>>
    {
        IBaseRepository<Elementtype> elementHandel;

        public SelectElementCommandHandel(IBaseRepository<Elementtype> elementHandel)
        {
            this.elementHandel = elementHandel;
        }
        /// <summary>
        /// 元素下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<ApiResult<List<SelectElementDto>>> Handle(SelectElementCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<SelectElementDto>> result = new ApiResult<List<SelectElementDto>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();

            var list = from a in elementHandel.GetAll()
                       select new SelectElementDto
                       {
                           ElementtypeId = a.ElementtypeId,
                           ElementNum = a.ElementNum,
                       };

            result.Data = list.ToList();
            return Task.FromResult(result);

        }
    }
}
